<?php

namespace App\Console\Commands;

use App\Console\Base;
use App\Models\AdminLog;
use App\Models\HallConfig;
use common\enum\CommonEnum;
use Illuminate\Support\Facades\Log;

class HallSignInLog extends Base
{
    const ONE_DAY_TIME = 86400;//一天的秒数
    /**
     * 控制台命令 signature 的名称。
     *
     * @var string
     */
    protected $signature = self::PREFIX . 'hallsigninlog {--hall_id=}';


    /**
     * 控制台命令说明。
     *
     * @var string
     */
    protected $description = 'HallSignInLog';

    /**
     * 执行控制台命令。
     *
     * @return mixed
     */
    public function handle()
    {
        $hallID  = $this->option('hall_id');

        $logData = AdminLog::select('created_at')->where(['hall_id' => $hallID])->orderBy('id', 'desc')->first();
        if(empty($logData)){
            Log::info('$logData null');
            return true;
        }
        $logTime = strtotime($logData['created_at']);
//        $logTime = '1542195219';
        $minTime = time() - self::ONE_DAY_TIME;
        if ($logTime <= $minTime) {
            $hallUpdate = [
                'status'          => CommonEnum::STATUS_FREEZE,
                'is_admin_freeze' => CommonEnum::STATUS_ENABLED,//1为厅冻结，0正常
                'is_user_freeze'  => CommonEnum::STATUS_DISABLE,//1为厅冻结，0正常
            ];
            HallConfig::where(['hall_id' => $hallID])->update($hallUpdate);
            $this->info('冻结 Hall Id  ' . $hallID);
        }
    }
}
